from wsgiref.simple_server import make_server
import wsgiref.util
import time


def handle_cgi(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    fname = wsgiref.util.shift_path_info(environ)
    return [fname]

def handle_method(environ, start_response):
    start_response('200 OK', [('Content-Type', 'text/html')])
    mname = wsgiref.util.shift_path_info(environ)
    return [mname]

def myapp(environ, start_response):
    rqtype = wsgiref.util.shift_path_info(environ)

    if rqtype == 'cgi-bin':
        return handle_cgi(environ, start_response)
    if rqtype == 'method':
        return handle_method(environ, start_response)

    start_response('200 OK', [('Content-Type', 'text/html')])
    return ['not found']

httpd = make_server('', 8081, myapp)
print "Serving HTTP on port 8081..."

# Respond to requests until process is killed
httpd.serve_forever()

# Alternative: serve one request, then exit
httpd.handle_request()
